package com.yonxao.demo.crud.annotation.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.yonxao.demo.crud.core.IEntityEnum;

import java.io.IOException;

/**
 * 实体枚举属性的序列化方法
 *
 * @author yonxao
 * @date 2021/3/20
 */
public class EntityEnumSerializer extends JsonSerializer<Object> {

    @Override
    public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(((IEntityEnum) o).getCode());
    }
}